//
//  JKBaseViewController.swift
//  afanti
//
//  Created by albert on 16/4/16.
//  Copyright © 2016年 albert. All rights reserved.
//

import UIKit

protocol JKBaseViewControllerDelegate: NSObjectProtocol {
    
    func baseViewControllerDidClickAnswer(baseViewController: JKBaseViewController, button: UIButton)
}

class JKBaseViewController: UIViewController {
    
    //保存代理
    weak var delegate: JKBaseViewControllerDelegate?
    
    var labelText: String?{
        didSet{
            setLabeText(labelText!)
        }
    }
    
    var btnText: String?{
        didSet{
            setAnswerQuestionBtn(btnText!)
        }
    }
    
    lazy var imageView: UIImageView = {
        
        let imageView = UIImageView()
        imageView.image = UIImage(named: "aft_no_message")
        imageView.width = 135
        imageView.height = 117
        imageView.center = self.view.center
        
        return imageView
    }()
    
    lazy var label: UILabel = {
        let label = UILabel()
        
        label.height = 25
        label.width = self.view.width
        label.x = 0
        label.y = CGRectGetMaxY(self.imageView.frame) + 10
        
        label.font = UIFont.systemFontOfSize(13)
        label.textAlignment = NSTextAlignment.Center
        label.textColor = UIColor(red: 144/255.0, green: 144/255.0, blue: 144/255.0, alpha: 1)
        
        return label
    }()
    
    lazy var btn: UIButton = {
        let btn = UIButton()
        
        btn.height = 25
        btn.width = self.imageView.width
        btn.centerX = self.imageView.centerX
        btn.y = CGRectGetMaxY(self.label.frame) + 10
        
        btn.titleLabel?.font = self.label.font
        
        btn.setTitleColor(UIColor(red: 35/255.0, green: 151/255.0, blue: 68/255.0, alpha: 1), forState: UIControlState.Normal)
        
        btn.addTarget(self, action: "btnClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(imageView)
    }

    
    /** label */
    func setLabeText(text: String){
        
        label.text = text
        view.addSubview(label)
    }
    
    /** 回答问题 */
    func setAnswerQuestionBtn(text: String){
        btn.setTitle(text, forState: UIControlState.Normal)
        view.addSubview(btn)
    }
    
    /** 点击回答问题 */
    func btnClick(button: UIButton){
        if ((delegate?.respondsToSelector("baseViewControllerDidClickAnswer:")) != nil){
            delegate?.baseViewControllerDidClickAnswer(self, button: button)
        }
    }
}
